<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="11">
            <a-form-item
                label="学号"
            >
              <a-input v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="11">
            <a-form-item
                label="姓名"
            >
              <a-input v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="11">
              <a-form-item label="院系">
                <a-select allowClear v-model="queryParam.ssyxm" @change="yxChange" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

          <template v-if="advanced">
            <a-col :md="6" :sm="11">
              <a-form-item label="专业">
                <a-select allowClear v-model="queryParam.sszym" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.zyList" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="11">
              <a-form-item
                label="论文题目"
              >
                <a-input v-model="queryParam.lwtm"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="11">
              <a-form-item
                label="授予学位的大学"
              >
                <a-input v-model="queryParam.syxwddx"/>
              </a-form-item>
            </a-col>

          </template>
          <a-col :md="16" :sm="24">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 8px">查询</a-button>
              <a-button type="primary" @click="exportExcel">导出</a-button>
              <a-button type="primary" @click="batchCheck" style="margin:0 10px">批量审核</a-button>
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :alert="options.alert"
        :rowSelection="options.rowSelection"
        :pageSize="parameter.pageSize"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter.pageNo - 1) * parameter.pageSize }}
        </span>
        <template slot="action" slot-scope="id,b">
          <a @click="showCheck(b)">审核</a>
        </template>
      </s-table>
    </a-card>

    <check-modal
      ref="check"
      :visible="visible"
      :pageType="'bsbylw'"
      :id="checkId"
      @cancel="visible = false"
      @refresh="refresh"
    />
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import checkModal from './checkModal'
import moment from 'moment';
import { DateToString } from '@/utils/common'

export default {
  data () {
    return {
      advanced: true,
      queryParam: {
        sszym: ''
      },
      columns: [
        {
          title: '序号',
          width: '80px',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: "学号",
          width: '150px',
          dataIndex: 'xh'
        },
        {
          title: "姓名",
          width: '100px',
          dataIndex: 'xm'
        },
        {
          title: "院系",
          width: '150px',
          dataIndex: 'ssyxmc'
        },
        {
          title: "专业",
          width: '150px',
          dataIndex: 'sszymc'
        },
        {
          title: "论文题目",
          // width: '180px',
          dataIndex: 'lwtm'
        },
        {
          title: '专业领域',
          width: '180px',
          dataIndex: 'zyly'
        },
        {
          title: '授予学位的大学',
          width: '120px',
          dataIndex: 'syxwddx'
        },
        {
          title: '审核状态',
          width: '120px',
          dataIndex: 'shztmc'
        },
        {
          title: "操作",
          width: '80px',
          dataIndex: 'id',
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      parameter: {
        pageNo: 1,
        pageSize: 10
      },
      loadData: parameter => {
        this.parameter = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        DateToString(params,'YYYY-MM')
        return this.$api.overseas.paperCheckList(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectedRowKeys: [],
      options: {
        alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      },
      selectMenu: {},
      visible: false,
      checkId: null
    }
  },
  components: {STable, checkModal},
  computed: {
    ...mapState({
      TYPE0503: state => state.app['TYPE0503'],
      TYPE0075: state => state.app['TYPE0075']
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0075')
    this.$store.dispatch('app/setDictionary', 'TYPE0503')
    this.initSelectMenu()
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yxList: res[0].data
        }
      })
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$set(this.queryParam, 'zyh', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zyList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zyList', [])
      }
    },
    onSelectChange (selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    refresh () {
      this.selectedRowKeys = []
      this.$refs.table.refresh(true)
      this.$refs.table.clearSelected()
    },
    showCheck (info) {
      this.visible = true
      this.checkId = info.id
      this.$refs.check.info = info
      this.$nextTick(() => {
        this.$refs.check.form.resetFields()
      })
    },
    batchCheck () {
      if (!this.selectedRowKeys.length) {
        this.$message.warning('请选择需要审核的学生')
        return
      }
      this.visible = true
      this.checkId = this.selectedRowKeys.join(',')
    },
    exportExcel () {
      let params = {...this.queryParam}
      delete params.pageNum
      this.$export('/xn/bsbylw/export/yjyDsh', params)
    }
  }
}
</script>

<style>

</style>
